<template>
  <div class="header">
    <!--头部左边 -->
    <div class="l-content">
      <!-- 收缩按钮 -->
      <el-button size="small" @click="handleCollapse()">
        <component class="icons" is="menu"></component>
      </el-button>
      <!-- 面包屑 -->
      <el-breadcrumb separator="/" class="bread">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <!-- 头部右边 -->
    <div class="r-content">
      <el-dropdown>
        <span class="el-dropdown-link">
          <img :src="userInfoList.icon" class="user" />
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item @click="Information">个人中心</el-dropdown-item>
            <el-dropdown-item @click="handleLoginOut">退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
    <el-drawer v-model="drawer" size="50%" :with-header="false">
      <UserInfo />
    </el-drawer>
  </div>
</template>

<script setup>
import { ref, computed, defineAsyncComponent } from "vue";
import { useAllDataStore } from "@/stores";
import { useRouter } from "vue-router";
const userInfoList = JSON.parse(localStorage.getItem("userInfo"));

const UserInfo = defineAsyncComponent(() =>
  import("@/views/user/Information.vue")
);
let drawer = ref(false);
const router = useRouter();

const store = useAllDataStore();
const handleCollapse = () => {
  store.state.isCollapse = !store.state.isCollapse;
};
const getImgUrl = (user) => {
  return new URL(`../assets/images/${user}.png`, import.meta.url).href;
};

const handleLoginOut = () => {
  store.clean();
  router.push("/login");
};

const Information = () => {
  drawer.value = true;
  // router.push("/userInfo");
};
</script>

<style lang="less" scoped>
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 100%;
  background-color: #333;
}
.icons {
  width: 20px;
  height: 20px;
}
.l-content {
  display: flex;
  align-items: center;
  .el-button {
    margin-right: 20px;
  }
}
.r-content {
  .user {
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }
}
:deep(.bread span) {
  color: #fff !important;
  cursor: pointer !important;
}
</style>
